﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Web;

namespace TaDMS.Models
{
    public class DeviceRepository : Repository<Device>
    {
        public DeviceRepository(DbContext model)
            : base(model)
        {
        }

        public IEnumerable<Device> GetData(out int? total, int? categoryId, IList<Expression<Func<Device, bool>>> multiFilter = null, string includeProperties = "", bool isPaging = false, int start = 0, int limit = 50)
        {
            List<int?> categoryIds;
            using (var db = new TaDMS())
            {
                categoryIds = db.sp_DeviceCategory_GetAllChildren(categoryId).ToList();
            }


            var data = base.GetData(out total, filter: v => categoryIds.Contains(v.DeviceCategoryId),
                                    includeProperties: includeProperties, isPaging: isPaging,
                                    orderBy: devices => devices.OrderBy(v => v.Serial), start: start, limit: limit, multiFilter: multiFilter);
            return data;
        }

    }
}